﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PassthroughStream.cs" company="Marcin Jastrzebski">
//   Copyright (c) Marcin Jastrzebski (marcin@marcinj.net)
// </copyright>
// <summary>
//   A stream that does nothing. Useful for debugging stream disposed exceptions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace KeePassLibRT.WinRT
{
    using System.IO;

    /// <summary>A stream that does nothing. Useful for debugging stream disposed exceptions.</summary>
    public class PassthroughStream : Stream
    {
        #region Fields

        /// <summary>The stream.</summary>
        private readonly Stream stream;

        #endregion

        #region Constructors and Destructors

        /// <summary>Initializes a new instance of the <see cref="PassthroughStream"/> class.</summary>
        /// <param name="stream">The stream.</param>
        public PassthroughStream(Stream stream)
        {
            this.stream = stream;
        }

        #endregion

        #region Public Properties

        /// <summary>Gets a value indicating whether can read.</summary>
        public override bool CanRead
        {
            get
            {
                return this.stream.CanRead;
            }
        }

        /// <summary>Gets a value indicating whether can seek.</summary>
        public override bool CanSeek
        {
            get
            {
                return this.stream.CanSeek;
            }
        }

        /// <summary>Gets a value indicating whether can write.</summary>
        public override bool CanWrite
        {
            get
            {
                return this.stream.CanWrite;
            }
        }

        /// <summary>Gets the length.</summary>
        public override long Length
        {
            get
            {
                return this.stream.Length;
            }
        }

        /// <summary>Gets or sets the position.</summary>
        public override long Position
        {
            get
            {
                return this.stream.Position;
            }

            set
            {
                this.stream.Position = value;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>The flush.</summary>
        public override void Flush()
        {
            this.stream.Flush();
        }

        /// <summary>The read.</summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public override int Read(byte[] buffer, int offset, int count)
        {
            return this.stream.Read(buffer, offset, count);
        }

        /// <summary>The seek.</summary>
        /// <param name="offset">The offset.</param>
        /// <param name="origin">The origin.</param>
        /// <returns>The <see cref="long"/>.</returns>
        public override long Seek(long offset, SeekOrigin origin)
        {
            return this.stream.Seek(offset, origin);
        }

        /// <summary>The set length.</summary>
        /// <param name="value">The value.</param>
        public override void SetLength(long value)
        {
            this.stream.SetLength(value);
        }

        /// <summary>The write.</summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        public override void Write(byte[] buffer, int offset, int count)
        {
            this.stream.Write(buffer, offset, count);
        }

        #endregion

        #region Methods

        /// <summary>The dispose.</summary>
        /// <param name="disposing">The disposing.</param>
        protected override void Dispose(bool disposing)
        {
            this.stream.Dispose();
            base.Dispose(disposing);
        }

        #endregion
    }
}